package com.omnisyr.textrebuilder.common;

import java.util.Comparator;

public class Coord3D {

	private int x;
	private int y;
	private int z;

	public Coord3D(int x, int y, int z) {

		this.x = x;
		this.y = y;
		this.z = z;

	}

	public int squreDistanceTo(Coord3D coord) {

		return getSqureMeter(this.x, coord.x) + getSqureMeter(this.y, coord.y) + getSqureMeter(this.z, coord.z);

	}

	private int getSqureMeter(int a, int b) {

		int dif = a - b;

		return dif * dif;

	}

	public int x() {

		return this.x;

	}

	public int y() {

		return this.y;

	}

	public int z() {

		return this.z;

	}

	@Override
	public String toString() {

		return "x: " + this.x + "\ny: " + this.y + "\nz: " + this.z;

	}

	public static final Comparator<Coord3D> comparator = Coord3D::compareWithCoord;

	private static int compareWithCoord(Coord3D a, Coord3D b) {

		if (a.x == b.x) {

			if (a.y == b.y) {

				if (a.z == b.z) {

					return 0;

				}

				return Integer.compare(a.z, b.z);

			}

			return Integer.compare(a.y, b.y);

		}

		return Integer.compare(a.x, b.x);

	}

}
